package com.ss.android.newmedia.feedback;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.article.browser.R;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.ui.view.SwipeOverlayFrameLayout;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.image.BaseImageManager;
import com.ss.android.image.loader.LargeImageLoader;
import com.ss.android.newmedia.NewMediaConstants;
import com.ss.android.newmedia.activity.FragmentActivity;

import java.io.File;

public class FeedbackActivity extends FragmentActivity {
    String a;
    TextView b;
    WebView c;
    com.ss.android.image.n d;
    LargeImageLoader e;
    BaseImageManager f;
    TaskInfo g;
    boolean h;
    private TextView i;
    private TextView j;
    private boolean k;
    private boolean l;
    private View m;
    private SwipeOverlayFrameLayout n;
    private View o;
    private FragmentManager p;
    private k q;
    public FeedbackActivity() {

        this.a = null;
        this.k = true;
        this.h = false;
    }

    public static void a(Context arg2, String arg3, WeakHandler arg4) {
        new a(arg2, arg3, arg4).execute(new Object[0]);
    }

    public int getLayout() {
        return R.layout.feedback_activity;
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode != 1001) {
            super.onActivityResult(requestCode, resultCode, intent);
        } else if (resultCode == -1) {
            Fragment v0 = this.getSupportFragmentManager().findFragmentByTag("_my_");
            if ((v0 instanceof k)) {
                ((k) v0).a = true;
            }
        }
    }

    public void onBackPressed() {
        if (!this.isFinishing()) {
            Intent v0 = null;
            if (this.isTaskRoot()) {
                v0 = ToolUtils.getLaunchIntentForPackage(((Context) this), this.getPackageName());
            }

            this.finish();
            if (v0 == null) {
                return;
            }

            this.startActivity(v0);
        }
    }

    public void onCreate(Bundle savedInstanceState) {
        String v0_2;
        int v2;
        String v1 = null;
        int v9 = 2;
        boolean v3 = true;
        int v5 = 0;
        super.onCreate(savedInstanceState);
        this.findViewById(com.ss.android.article.browser.R.id.title_bar);
        this.c = (WebView) this.findViewById(R.id.web_container);
        this.c.getSettings().setJavaScriptEnabled(true);
        this.b = (TextView) this.findViewById(R.id.indicator_left);
        this.b.setOnClickListener(new b(this));
        this.i = (TextView) this.findViewById(R.id.back);
        this.i.setOnClickListener(new com.ss.android.newmedia.feedback.c(this));
        this.j = (TextView) this.findViewById(R.id.title);
        this.j.setText(com.ss.android.article.browser.R.string.title_feedback);
        this.o = this.findViewById(com.ss.android.article.browser.R.id.write_btn);
        this.o.setOnClickListener(new com.ss.android.newmedia.feedback.d(this));
        ((TextView) this.findViewById(com.ss.android.article.browser.R.id.post_comment)).setText(com.ss.android.article.browser.R.string.info_input_here);
        this.m = this.findViewById(com.ss.android.article.browser.R.id.night_mode_overlay);
        View v0 = this.findViewById(com.ss.android.article.browser.R.id.swipe_overlay);
        if ((v0 instanceof SwipeOverlayFrameLayout)) {
            this.n = ((SwipeOverlayFrameLayout) v0);
        }

        if ((this.l) && this.n != null) {
            this.n.setOnSwipeListener(new e(this));
        }

        Intent v0_1 = this.getIntent();
        if (v0_1 != null) {
            this.a = v0_1.getStringExtra("key_appkey");
            this.l = v0_1.getBooleanExtra("use_swipe", false);
            this.h = v0_1.getBooleanExtra("slide_out_left", false);
            v2 = v0_1.getIntExtra("tab_name", 1);
            v0_2 = v0_1.getStringExtra("anchor");
        } else {
            v0_2 = v1;
            v2 = 1;
        }

        if (this.a == null) {
            this.a = "";
        }

        this.k = this.getResources().getBoolean(R.bool.t);
        this.f = new BaseImageManager(((Context) this));
        this.g = new TaskInfo();
        Bundle v4 = new Bundle();
        v4.putString("key_appkey", this.a);
        this.q = new k();
        this.q.setArguments(v4);
        StringBuilder v4_1 = new StringBuilder().append(NewMediaConstants.faqV2Url).append("?night_mode=");
        com.ss.android.j.b.isNightModeToggled();
        String v4_2 = AppLog.a(v4_1.append(0).toString(), false);
        v0_2 = !android.support.design.a.isTextEmpty(v0_2) ? v4_2 + "#" + v0_2 : v4_2;
        this.p = this.getSupportFragmentManager();
        FragmentTransaction v4_3 = this.p.beginTransaction();
        v4_3.add(com.ss.android.article.browser.R.id.fragment_container, this.q, "_my_");
        v4_3.commit();
        TextView v4_4 = this.b;
        if (v9 == v2) {
            v3 = false;
        }

        v4_4.setSelected(v3);
        WebView v3_1 = this.c;
        if (v9 != v2) {
            v5 = 8;
        }

        v3_1.setVisibility(v5);
        TTUtils.a(v0_2, this.c, v1);
        com.ss.android.newmedia.feedback.a.a();
        com.ss.android.newmedia.feedback.a.e();
    }

    public void onDestroy() {
        if (this.d != null) {
            this.d.dismiss();
            this.d = null;
        }

        super.onDestroy();
        if (this.e != null) {
            this.e.b();
        }

        if (this.g != null) {
            this.g.a = true;
        }
    }

    public void onResume() {
        int v1 = 8;
        super.onResume();
        if (this.e != null) {
            this.e.a();
        }

        if (this.k) {
            this.m.setVisibility(v1);
        } else {
            com.ss.android.j.b.isNightModeToggled();
            this.m.setVisibility(v1);
        }
    }

    public void onStop() {
        super.onStop();
        if (this.e != null) {
            this.e.a.pause();
        }
    }

    static final class a extends AsyncTask {
        private final Context a;
        private final String b;
        private final WeakHandler c;

        public a(Context arg2, String arg3, WeakHandler arg4) {

            this.a = arg2.getApplicationContext();
            this.b = arg3;
            this.c = arg4;
        }

        private Void a() {
            long v6 = 0;
            try {
                long v4 = com.ss.android.newmedia.feedback.f.a(this.a).a(true);
                if (this.a.getFilesDir() != null) {
                    File v0_1 = new File(this.a.getFilesDir().getParent() + "/shared_prefs", "feedback_last_time.xml");
                    if (v0_1.exists()) {
                        if (v4 <= v6) {
                            SharedPreferences v1 = this.a.getSharedPreferences("feedback_last_time", 0);
                            if (v1.contains("key_last_time")) {
                                v4 = v1.getLong("key_last_time", -1);
                            }
                        }

                        v0_1.delete();
                    }
                }

                new j(this.c, this.a, new n(this.b, 0, v4, 50, 0, 2)).start();
            } catch (Exception v0) {
            }

            return null;
        }

        protected final Object doInBackground(Object[] arg2) {
            return this.a();
        }
    }
}

